<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('历史客户列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="col-sm-12">
        <a id="reAdd" class="col-sm-2" href="/qianhuankuan/qianhuankuanTest/add">
            返回添加页面
        </a>
        <div class="col-sm-10">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="kehuName"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
    </div>
<!--    <form class="form-horizontal m" id="form-qianhuankuanTest-add">-->
<!--        <div th:with="type=${@qiankuantongjiServiceImpl.selectAllQiankuantongjiList2All(session.name4user)}">-->
<!--            <div class="form-group" th:each="lists : ${type}">-->
<!--            <input type="checkbox" class="col-sm-1 control-label">-->
<!--            <div class="col-sm-7">-->
<!--                <input name="beizhu" readonly class="form-control" type="text" th:value="${lists.getKehuName()}">-->
<!--            </div>-->
<!--            <div class="col-sm-3">-->
<!--                <input name="beizhu" readonly class="form-control" type="text" th:value="'金额为：'+${lists.getJiner()}">-->
<!--            </div>-->
<!--        </div>-->
<!--        </div>-->
<!--    </form>-->
    <div class="col-sm-12 select-table table-striped">
        <table id="bootstrap-table"></table>
    </div>
<!--    <form hidden="hidden" id="form-Check2Add">-->
<!--        <input name="msg" id="Check2Add" type="text">-->
<!--    </form>-->

</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">

    var prefix = ctx + "qianhuankuan/qianhuankuanTest"
    $("#form-qianhuankuanTest-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var msgStr = ""
        if ($.validate.form()) {
            var _2length_ = $('table[id="bootstrap-table"]').children('tbody').children('tr').length
            for (let i = 0; i <_2length_; i++) {
                var f_father = $('table[id="bootstrap-table"]').children('tbody').children('tr')[i];
                if (f_father.children[0].children[0].children[0].checked){
                    msgStr = msgStr + "@" + f_father.children[1].innerHTML + ";"
                }
            }
            // $('#Check2Add').attr("value",msgStr)

            $.ajax({
                type:"POST",
                datatype: "string",
                url: "/qianhuankuan/qianhuankuanTest/Check2Add",
                data: {"msg": msgStr},
                success: function (result) {
                    if (result==="CheckName") {
                        document.getElementById("reAdd").click()
                    }
                    else {
                        alert(result)
                    }
                },
                error : function(result) {
                    console.log(result.data)
                    if (result.data===undefined){
                        alert("没有勾选任何一项")
                    }
                    if (result.data===-1){
                        alert("勾选了多项，此处仅可勾选一项")
                    }
                }
            });


        }
    }
    $(function() {
        var options = {
            url: prefix + "/list2AllQian",
            modalName: "欠还款表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'kehuName',
                    title: '客户名称'
                },
                {
                    field: 'jiner',
                    title: '当前欠款金额'
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>